<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>分时候问候语</title>
    <style>
      img {
        width: 150px;
      }
    </style>
  </head>
  <body>
    <img src="./imgs/zao.gif" />
    <div>上午好</div>

    <script>
      var img = document.querySelector('img');
      var div = document.querySelector('div');

      var dt = new Date();
      var hour = dt.getHours();

      if (hour < 12) {
        img.src = './imgs/zao.gif';
        div.innerHTML = '上午好';
      } else if (hour >= 12 && hour < 18) {
        img.src = './imgs/xia.gif';
        div.innerHTML = '下午好';
      } else {
        img.src = './imgs/wan.gif';
        div.innerHTML = '晚上好';
      }
    </script>
  </body>
</html>
